package top.cptr.so.aliyundomainserver.controller;

import com.aliyun.alidns20150109.models.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.CreateClientException;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.RequestInterfaceException;
import top.cptr.so.aliyundomainserver.pojo.R;
import top.cptr.so.aliyundomainserver.service.ResolverManage;

/**
 * 解析管理接口
 */
@RestController
@RequestMapping("/resolverManage")
public class ResolverManageController {
    @Autowired
    private ResolverManage resolverManage;

    /**
     * 获取解析记录列表
     * @param param
     * @param token
     * @param r
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/describeDomainRecords")
    public R describeDomainRecords(DescribeDomainRecordsRequest param,String token,R r) throws CreateClientException, RequestInterfaceException {
        DescribeDomainRecordsResponseBody body = resolverManage.describeDomainRecords(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }
    @PostMapping(value = "/describeDomainRecords",produces = "application/json")
    public R describeDomainRecords(@RequestBody  DescribeDomainRecordsRequest param, R r, String token) throws CreateClientException, RequestInterfaceException{
        return describeDomainRecords(param, token, r);
    }


    /**
     * 获取解析记录详细信息
     * @param param
     * @param token
     * @param r
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/describeDomainRecordInfo")
    public R describeDomainRecordInfo(DescribeDomainRecordInfoRequest param, String token, R r) throws CreateClientException, RequestInterfaceException {
        DescribeDomainRecordInfoResponseBody body = resolverManage.describeDomainRecordInfo(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }
    @PostMapping(value = "/describeDomainRecordInfo",produces = "application/json")
    public R describeDomainRecordInfo(@RequestBody DescribeDomainRecordInfoRequest param, R r, String token) throws CreateClientException, RequestInterfaceException {
        return describeDomainRecordInfo(param, token, r);
    }

    /**
     * 获取子域名解析记录列表
     * @param param
     * @param r
     * @param token
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/describeSubDomainRecords")
    public R describeSubDomainRecords(DescribeSubDomainRecordsRequest param, R r, String token) throws CreateClientException, RequestInterfaceException {
        DescribeSubDomainRecordsResponseBody body = resolverManage.describeSubDomainRecords(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }
    @PostMapping(value = "/describeSubDomainRecords",produces = "application/json")
    public R describeSubDomainRecords(@RequestBody DescribeSubDomainRecordsRequest param, String token, R r) throws CreateClientException, RequestInterfaceException {
        return describeSubDomainRecords(param, r, token);
    }

    /**
     * 添加解析记录
     * @param param
     * @param r
     * @param token
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/addDomainRecord")
    public R addDomainRecord(AddDomainRecordRequest param,R r,String token) throws CreateClientException, RequestInterfaceException {
        AddDomainRecordResponseBody body = resolverManage.addDomainRecord(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }

    @PostMapping(value = "/addDomainRecord",produces = "application/json")
    public R addDomainRecord (@RequestBody AddDomainRecordRequest param,String token,R r) throws CreateClientException, RequestInterfaceException{
    return addDomainRecord(param, r, token);
    }

    /**
     * 删除解析记录
     * @param param
     * @param r
     * @param token
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/deleteDomainRecord")
    public R deleteDomainRecord(DeleteDomainRecordRequest param,R r,String token) throws CreateClientException, RequestInterfaceException {
        DeleteDomainRecordResponseBody body = resolverManage.deleteDomainRecord(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }
    @PostMapping(value = "/deleteDomainRecord",produces = "application/json")
    public R deleteDomainRecord(@RequestBody DeleteDomainRecordRequest param,String token,R r) throws CreateClientException, RequestInterfaceException {
        return deleteDomainRecord(param, r, token);
    }


    /**
     * 修改解析记录
     * @param param
     * @param r
     * @param token
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/updateDomainRecord")
    public R updateDomainRecord(UpdateDomainRecordRequest param,R r,String token) throws CreateClientException, RequestInterfaceException{
        UpdateDomainRecordResponseBody body = resolverManage.updateDomainRecord(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }

    @PostMapping(value = "/updateDomainRecord",produces = "application/json")
    public R updateDomainRecord(@RequestBody UpdateDomainRecordRequest param,String token,R r) throws CreateClientException, RequestInterfaceException{
        return updateDomainRecord(param, r, token);
    }

    /**
     * 删除子域名解析记录
     * @param param
     * @param r
     * @param token
     * @return
     * @throws CreateClientException
     * @throws RequestInterfaceException
     */
    @GetMapping("/deleteSubDomainRecords")
    public R deleteSubDomainRecords(DeleteSubDomainRecordsRequest param,R r,String token) throws CreateClientException, RequestInterfaceException{
        DeleteSubDomainRecordsResponseBody body = resolverManage.deleteSubDomainRecords(token, param);
        r.setStatus(true);
        r.setData(body);
        return r;
    }
    @PostMapping(value = "/deleteSubDomainRecords",produces = "application/json")
    public R deleteSubDomainRecords(@RequestBody DeleteSubDomainRecordsRequest param,String token,R r) throws CreateClientException, RequestInterfaceException{
        return deleteSubDomainRecords(param, r, token);
    }

}
